package com.ruoyi.web.controller.admin;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PetPublish;
import com.ruoyi.system.service.IPetPublishService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 宠物发布Controller
 */
@RestController
@RequestMapping("/publish")
public class PublishController extends BaseController {
    @Autowired
    private IPetPublishService petPublishService;

    /**
     * 查询宠物发布列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PetPublish petPublish) {
        startPage();
        petPublish.setPublisherId(SecurityUtils.getUserId());
        List<PetPublish> list = petPublishService.selectPetPublishList(petPublish);
        return getDataTable(list);
    }

    /**
     * 导出宠物发布列表
     */
    @Log(title = "导出宠物发布列表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PetPublish petPublish) {
        List<PetPublish> list = petPublishService.selectPetPublishList(petPublish);
        ExcelUtil<PetPublish> util = new ExcelUtil<PetPublish>(PetPublish.class);
        return util.exportExcel(list, "publish");
    }

    /**
     * 获取宠物发布详细信息
     */
    @GetMapping(value = "/get/{publishId}")
    public AjaxResult getInfo(@PathVariable("publishId") Long publishId) {
        return success(petPublishService.selectPetPublishById(publishId));
    }

    /**
     * 新增宠物发布
     */
    @Log(title = "宠物发布", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody PetPublish petPublish) {
        return toAjax(petPublishService.insertPetPublish(petPublish));
    }

    /**
     * 修改宠物发布
     */
    @Log(title = "修改宠物发布", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody PetPublish petPublish) {
        return toAjax(petPublishService.updatePetPublish(petPublish));
    }

    /**
     * 删除宠物发布
     */
    @Log(title = "删除宠物发布", businessType = BusinessType.DELETE)
    @PostMapping("/del/{publishIds}")
    public AjaxResult remove(@PathVariable Long[] publishIds) {
        return toAjax(petPublishService.deletePetPublishByIds(publishIds));
    }
}
